<?php session_start();?>
<html>
<head>
	<title>Survey</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
	<meta name="format-detection" content="telephone=no" />
	
	<link rel="stylesheet" href="css/style.css" />
</head>
<body>
	<form action="confirm.php" method="post">
	<select name="company" id="company">
<?php
include 'config.php';

$comp_id = $_POST['company'];

$_SESSION['comp_id'] = $comp_id;

$conn = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db("mweb_survey");

$sql_comp = "SELECT * FROM company";
$result_comp = mysql_query($sql_comp, $conn) or die(mysql_error());

while ($row_comp = mysql_fetch_assoc($result_comp)) {
	$row_comp_id = $row_comp['CompID'];
	$row_comp_name = $row_comp['CompName'];
	if ($comp_id == $row_comp_id) {
		echo "<option selected='selected' value='$row_comp_id'>$row_comp_name</option>";
	} else {
		echo "<option value='$row_comp_id'>$row_comp_name</option>";
	}
}
?>
	</select>
	<br/>
	<input type="submit" value="Get Company" />
	</form>

<?php
// if (isset($_POST['company'])) {
	// $comp_id = $_POST['company'];
// }
// if (isset($_REQUEST['comp_id'])) {
	// $comp_id = $_REQUEST['comp_id'];
// }

$sql_comp = "SELECT * FROM company WHERE CompID='$comp_id'";
$result_comp = mysql_query($sql_comp, $conn) or die(mysql_error());

$row_comp = mysql_fetch_assoc($result_comp);
$comp_name = $row_comp['CompName'];
$comp_type = $row_comp['Type'];
$comp_sector = $row_comp['Sector'];
$comp_sub_sector = $row_comp['Subsector'];
$comp_addr = $row_comp['StreetAddr'] . ", " . $row_comp['City'] . ", " . $row_comp['State'] . ", " . $row_comp['Zip'];
$comp_phone = $row_comp['Phone'];
$comp_note = $row_comp['Notes'];
echo "Company ID: $comp_id<br/>";
echo "Company Name: $comp_name<br/>";
echo "Sector: $comp_sector<br/>";
echo "Subsector: $comp_sub_sector<br/>";
echo "Company Type: $comp_type<br/>";
echo "Address: <a href='map.php?address=$comp_addr&compName=$comp_name'>$comp_addr</a><br/>";
echo "Phone: <a href='tel:$comp_phone'>$comp_phone</a><br/>";
echo "Notes: $comp_note<br/>";
echo "<button onclick=\"window.location.href='question.php'\">OK</button>";
?>
<?php include 'footer.php';?>
</body>
</html>